#ifndef GU_CLIENT_H
#define GU_CLIENT_H

#include "../protocol/gu_protocol.h"
#include <stdbool.h>

// Client Configuration
typedef struct {
    char host[256];
    int port;
    char username[GU_MAX_USERNAME_SIZE];
    char password[GU_MAX_PASSWORD_SIZE];
    char database[GU_MAX_DATABASE_SIZE];
    bool interactive;
    bool verbose;
} gu_client_config_t;

// Client Context
typedef struct {
    gu_client_t connection;
    gu_client_config_t config;
    bool running;
    bool connected;
} gu_client_context_t;

// Client Functions

// Initialization and cleanup
gu_client_context_t* gu_client_create(void);
void gu_client_destroy(gu_client_context_t* ctx);
int gu_client_init_config(gu_client_context_t* ctx);

// Connection management
int gu_client_connect(gu_client_context_t* ctx);
int gu_client_disconnect(gu_client_context_t* ctx);
int gu_client_authenticate(gu_client_context_t* ctx);

// Command execution
int gu_client_execute_sql(gu_client_context_t* ctx, const char* sql);
int gu_client_query_sql(gu_client_context_t* ctx, const char* sql);
int gu_client_ping(gu_client_context_t* ctx);

// Interactive mode
int gu_client_interactive_mode(gu_client_context_t* ctx);
int gu_client_process_command(gu_client_context_t* ctx, const char* input);

// Command line interface
int gu_client_parse_args(gu_client_context_t* ctx, int argc, char* argv[]);
void gu_client_print_usage(const char* program_name);
void gu_client_print_help(void);

// Utility functions
void gu_client_print_result(gu_result_t* result);
void gu_client_print_select_result(gu_result_t* result);
const char* gu_client_get_prompt(gu_client_context_t* ctx);
int gu_client_read_line(char* buffer, size_t size);

// Built-in commands
int gu_client_cmd_connect(gu_client_context_t* ctx, const char* args);
int gu_client_cmd_disconnect(gu_client_context_t* ctx);
int gu_client_cmd_quit(gu_client_context_t* ctx);
int gu_client_cmd_help(gu_client_context_t* ctx);
int gu_client_cmd_status(gu_client_context_t* ctx);

// Built-in SQL commands
int gu_client_cmd_show_databases(gu_client_context_t* ctx);
int gu_client_cmd_show_tables(gu_client_context_t* ctx);
int gu_client_cmd_show_status(gu_client_context_t* ctx);
int gu_client_cmd_use_database(gu_client_context_t* ctx, const char* database);
int gu_client_cmd_describe_table(gu_client_context_t* ctx, const char* table);
int gu_client_cmd_show_create_table(gu_client_context_t* ctx, const char* table);
int gu_client_cmd_show_columns(gu_client_context_t* ctx, const char* table);

#endif // GU_CLIENT_H